package com.unimas.dof.render;

import java.util.Map.Entry;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.unimas.dof.DOFContext;
import com.unimas.dof.view.JspView;

public class JspRender implements DOFRender<JspView> {

	public void render(JspView view, DOFContext context) throws Exception {
		HttpServletRequest request = context.getRequest();
		HttpServletResponse response = context.getResponse();
		String action = request.getParameter("action");
		for(Entry<String,Object> entry: view.getAttributes().entrySet()){
            request.setAttribute(entry.getKey(), entry.getValue());
        }
		
		String path = view.getPath();
		if(path == null){
			path = "/"+action+".jsp";
		}
		RequestDispatcher rd = request.getRequestDispatcher(path);
        rd.forward(request, response);
	}

}
